/*
 * Copyright 2010. 
 * 
 * This document may not be reproduced, distributed or used 
 * in any manner whatsoever without the expressed written 
 * permission of xrkol Corp. 
 * 
 * $Rev: Rev $
 * $Author: Author $
 * $LastChangedDate: LastChangedDate $
 *
 */

package com.xrkol.sharelib.dao.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.xrkol.sharelib.dao.AttendanceDao;
import com.xrkol.sharelib.entity.Attendance;
import com.xrkol.sharelib.entity.Clazz;

/**
 * @author peng.xia
 *
 */
@Repository
public class AttendanceDaoImpl extends BaseDaoImpl<Attendance,String> implements AttendanceDao{

    @Override
    public List<Attendance> getStudentsByClass(Clazz clazz) {
        String queryString="from Attendance a where a.clazz=? order by a.createTime desc";
        return executeQueryWithoutPaging(queryString, clazz);
    }

    @Override
    public List<Attendance> getAll() {
        String queryString="from Attendance";
        return executeQueryWithoutPaging(queryString);
    }

    @Override
    public void deleteByClass(Clazz clazz) {
        String queryString="delete from Attendance a where a.clazz=?";
        executeUpdateOrDelete(queryString, clazz);
    }

    @Override
    public Attendance getByStudent(String studentId) {
        String queryString="from Attendance a where a.student.id = ?";
        List<Attendance> attendances=executeQueryWithoutPaging(queryString, studentId);
        return attendances.size()>0?attendances.get(0):null;
    }


}
